def is_valid_date(year, month, day):
    """验证输入的日期是否有效"""
    if not (isinstance(year, int) and isinstance(month, int) and isinstance(day, int)):
        return False

    # 检查月份范围
    if month < 1 or month > 12:
        return False

    # 获取每个月的最大天数
    days_in_month = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

    # 检查是否为闰年
    def is_leap_year(y):
        if y % 4 == 0:
            if y % 100 == 0:
                return y % 400 == 0
            else:
                return True
        else:
            return False

    # 更新二月的天数（如果是闰年）
    days_in_month[2] = 29 if is_leap_year(year) and month == 2 else 28

    # 检查日期范围
    if day < 1 or day > days_in_month[month]:
        return False

    return True


# 示例用法：
if __name__ == "__main__":
    import sys

    date_input = input("请输入一个日期（格式：YYYY MM DD）: ")

    try:
        parts = date_input.split()
        if len(parts) != 1:
            raise ValueError

        y, m, d = map(int, parts[0].split())

        # 验证并显示结果
        result = is_valid_date(y, m, d)
        leap_result = "是" if is_valid_date(y) else "否"

        print(f"\n日期 {y}-{m:02d}-{d} 是否有效：{'是' if result else '否'}")
        print(f"{year}年是否为闰年：{leap_result}")
    except Exception as e:
        print("输入无效，请确保格式正确！",)